/**
 * 
 */
package com.wolfpire.info.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.info.model.SchoolBaseInfo;
import com.wolfpire.info.service.SchoolBaseInfoService;
import com.wolfpire.system.common.AuthorityUtils;
import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.system.common.springmvc.PrincipalArgument;
import com.wolfpire.system.model.Authority;
import com.wolfpire.system.model.User;

/**
 * 学习基本信息控制器
 * @author lihd
 *
 */

@Controller
@RequestMapping(value = "/schoolBaseInfo")
public class SchoolBaseInfoController {
	
	@Resource SchoolBaseInfoService schoolBaseInfoService;
	
	@RequestMapping("/list")
	public ModelAndView list(@PrincipalArgument User user, @RequestParam Long menuId) {
		//获取对应菜单的操作权限
		List<Authority> operAuthorities = AuthorityUtils.getAperAuthorities(user, menuId);
		return new ModelAndView("info/schoolBaseInfo/schoolBaseInfo_list", "operAuthorities", operAuthorities);
	}
	
	@ResponseBody
	@RequestMapping("/queryList")
	public EasyuiPagination<SchoolBaseInfo> queryList(EasyuiPage<SchoolBaseInfo>page, SchoolBaseInfo filterSchoolBaseInfo) {
		Page<SchoolBaseInfo> schoolBaseInfos = this.schoolBaseInfoService.setPageDataList(page, filterSchoolBaseInfo);
		return new EasyuiPagination<SchoolBaseInfo>(schoolBaseInfos);
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpSession session, SchoolBaseInfo schoolBaseInfo) {
		ModelAndView mv = new ModelAndView("info/schoolBaseInfo/schoolBaseInfo_add");
		mv.getModelMap().addAttribute(schoolBaseInfo);
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public Result save(@PrincipalArgument User user, SchoolBaseInfo schoolBaseInfo) {
		try {
			schoolBaseInfo.setCreateUserId(user.getId());
			schoolBaseInfo.setCreateUserName(user.getNickName());
			this.schoolBaseInfoService.saveOrUpdate(schoolBaseInfo);
			return new Result(true, "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "保存失败");
		}
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(Long id) {
		ModelAndView mv = new ModelAndView("info/schoolBaseInfo/schoolBaseInfo_add");
		if (null != id) {
			SchoolBaseInfo schoolBaseInfo = this.schoolBaseInfoService.get(id);
			mv.addObject(schoolBaseInfo);
		}
		return mv;
	}
	
	@RequestMapping("/detail")
	public ModelAndView detail(@RequestParam(value = "id", required = true) Long id) {
		ModelAndView mv = new ModelAndView("info/schoolBaseInfo/schoolBaseInfo_detail");
		try {
			if (null != id) {
				SchoolBaseInfo schoolBaseInfo = this.schoolBaseInfoService.get(id);
				mv.addObject(schoolBaseInfo);
			}
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			return new ModelAndView("/proms/common/error");
		}
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Result delete(@RequestParam(value="id") Long id) {
		try {
			this.schoolBaseInfoService.del(id);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
}
